package com.foreverwin.mes.common.service.impl;

import com.foreverwin.mes.common.mapper.MobileWorkStationMapper;
import com.foreverwin.mes.common.model.ActivityOption;
import com.foreverwin.mes.common.model.MobileWorkStationData;
import com.foreverwin.mes.common.service.MobileWorkStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  移动维护服务实现类
 * </p>
 *
 * @author Syngna
 * @since 2020-01-04
 */
@Service
public class MobileWorkStationServiceImpl implements MobileWorkStationService {

    @Autowired
    private MobileWorkStationMapper mobileWorkStationMapper;

    @Override
    public List<MobileWorkStationData> listMobileWorkStationApplication(String site, String userBo, String workStation) {
        List<MobileWorkStationData> workStationDataList = mobileWorkStationMapper.selectMobileWorkStationList(site, userBo, workStation);
        if(workStationDataList == null || workStationDataList.size() == 0) {
            return new ArrayList<>();
        }
        List<String> activityList = workStationDataList.stream().map(MobileWorkStationData::getActivityBo).collect(Collectors.toList());
        List<ActivityOption> activityOptionList = mobileWorkStationMapper.selectActivityOptionList(activityList);
        for(MobileWorkStationData mobileWorkStationData : workStationDataList) {
            if(mobileWorkStationData.getActivityOptionList() == null) {
                mobileWorkStationData.setActivityOptionList(new ArrayList<>());
            }
            for(ActivityOption activityOption: activityOptionList) {
                if(activityOption.getActivity().equals(mobileWorkStationData.getActivity())) {
                    mobileWorkStationData.getActivityOptionList().add(activityOption);
                }
            }
        }
        return workStationDataList;
    }
}